from flask import Blueprint, request
from ..core import use_case_diag
from . import get_data, handle_error, params_check
from werkzeug.datastructures import FileStorage
# 路径配置
use_case_diag_blueprint = Blueprint('use_case_diag_blueprint', __name__, url_prefix='/use_case_diag')

# 前置处理器
@use_case_diag_blueprint.before_request
@handle_error
def before_request():
    get_data()

# omm文件处理
@use_case_diag_blueprint.route('/ava', methods=['POST'])
def handle():
    if request.method == 'POST':
        a: FileStorage = request.files.get('file') # 获取上传的文件
        b = a.stream.readlines()  # 读取文件内容
        return use_case_diag.getActorandUseCase(b) # 获取角色和用例个数
    else:
        return None

# 测试
@use_case_diag_blueprint.route('/trial', methods=['GET'])
def trial():
    return {'code': 200, 'msg': "Use Case Hello :)"}
